#include <sys/socket.h>
#include <cstring>
#include <cerrno>
#include <cstdio>
#include "ServerSocket.h"


using namespace yazi::socket;

ServerSocket::ServerSocket() : Socket() {}

ServerSocket::ServerSocket(const string& ip, const int port) : Socket(ip, port) {
    m_sockfd = ::socket(AF_INET, SOCK_STREAM, 0);
    if(m_sockfd < 0){
        perror("socket()");
        return;
    }
    set_nonblock();
    set_send_buffer(10 * 1024);
    set_recv_buffer(10 * 1024);
    set_linger(true, 0);
    set_keep_alive();
    set_reuse_addr();
    bind();
    listen(1024);
}

ServerSocket::~ServerSocket() {
    close();
}